home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
C-H
/
CHexDmpDA.cpt
/
Hex Dump DA
/
file.HexDumpDA.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-15
|
2KB
|
107 lines
#include <WindowMgr.h>
#include <StdFilePkg.h>
#include <FileMgr.h>
#include "HexDump.h"
extern long linesInFile;
extern long firstByte;
extern WindowPtr wp;
extern Cursor wait;
extern SFReply reply;
int fileRef = 0; /* the refnum of the file we're showing */
long fileSize; /* and the file's size (in bytes) */
#define LOCBUFSIZE 512L
doDumpTo()
{
long count, i;
char cr = 0x0D;
int outRef;
SFReply reply;
char buffer[LOCBUFSIZE];
Str255 dumpFileName;
long first;
static Point where = { 100, 104 };
char display[128];
GetWTitle( wp, dumpFileName );
pstrcat( dumpFileName, "\p dump");
SFPutFile(where, "\pDump to file:", dumpFileName, 0L, &reply);
if (!reply.good) return(0);
doUpdate();
FSDelete(reply.fName, reply.vRefNum);
Create( reply.fName, reply.vRefNum, '????', 'TEXT' );
if ( FSOpen( reply.fName, reply.vRefNum, &outRef ) == noErr) {
SetCursor(&wait);
SetFPos( fileRef, fsFromStart, first = 0L );
count = LOCBUFSIZE;
FSRead( fileRef, &count, buffer );
for (i=0; i<=linesInFile*16L; i+=16) {
if (i-first >= LOCBUFSIZE) {
first += count = LOCBUFSIZE;
FSRead( fileRef, &count, buffer );
}
Fill_Line( i, &buffer[i-first], display );
count = display[0];
display[++count]=cr;
FSWrite( outRef, &count, &display[1] );
}
FSClose( outRef );
InitCursor();
}
else SysBeep(3);
}
FSOpen_RF( fileName, vRefNum, refNum )
char *fileName;
int vRefNum;
int *refNum;
{
IOParam pb;
pb.ioCompletion = 0L;
pb.ioNamePtr = (StringPtr) fileName;
pb.ioVRefNum = vRefNum;
pb.ioMisc = 0L;
pb.ioVersNum = 0;
pb.ioPermssn = fsRdPerm;
PBOpenRF( &pb, 0 );
*refNum = pb.ioRefNum;
return pb.ioResult;
}
New_Open_File(newFileRef)
int newFileRef;
{
Close_File( fileRef );
fileRef = newFileRef;
GetEOF( fileRef, &fileSize );
New_File_Window( fileSize, reply.fName );
}
Open_Fork(fork, ref )
enum fork fork;
int *ref;
{
*ref = 0;
if (fork==data) {
if (No_Error(FSOpen(reply.fName, reply.vRefNum, ref)))
return 1;
}
else if (No_Error(FSOpen_RF(reply.fName, reply.vRefNum, ref)))
return 1;
if (*ref)
FSClose(*ref);
return 0;
}
Close_File(refNum)
int refNum;
{
if (refNum) FSClose(refNum);
}